package com.xn.app.muying.adpter;

import android.content.Context;
import android.graphics.Paint;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xn.app.muying.R;
import com.xn.app.muying.activity.BuyServiceActivity;
import com.xn.app.muying.bean.BuyTimeBean;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/10/14.
 */
public class BuyTimeAdapter extends BaseAdapter {
    private final LayoutInflater inflater;
    private Context context;
    private ArrayList<BuyTimeBean> list = new ArrayList<>();

    public BuyTimeAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void getData(ArrayList<BuyTimeBean> data) {
        this.list.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {

        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            view = inflater.inflate(R.layout.buytime_item, null);
            holder = new ViewHolder();
            holder.tv = (TextView) view.findViewById(R.id.buytime_item_tv);
            holder.tv2 = (TextView) view.findViewById(R.id.buytime_item_tv2);
            holder.tv3 = (TextView) view.findViewById(R.id.buytime_item_tv3);
            holder.iv = (ImageView) view.findViewById(R.id.buytime_item_iv);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.tv.setText(list.get(i).getName());
//        holder.tv2.setVisibility(View.VISIBLE);
//        holder.tv2.setText("原价：" + list.get(i).getOriginalPrice());
//        holder.tv2.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        if (BuyServiceActivity.mIndex == i) {
            holder.iv.setVisibility(View.VISIBLE);
            if (list.get(i).getDescription() != null && !list.get(i).getDescription().equals("") && !list.get(i).getDescription().equals("null")) {
                holder.tv3.setVisibility(View.VISIBLE);
                holder.tv3.setText(Html.fromHtml(list.get(i).getDescription()));
            }
        } else {
            holder.iv.setVisibility(View.GONE);
            holder.tv3.setVisibility(View.GONE);
        }
        return view;

    }

    class ViewHolder {
        TextView tv, tv2, tv3;
        ImageView iv;
    }
}
